using System.Collections.Generic;
using System.Linq;
using Magiq.Support;

namespace Magiq.Delete {
    public class EnumerableDelete<T> {
        private readonly EnumerableSourceFinder enumerableSourceFinder = new EnumerableSourceFinder();
        private readonly IEnumerable<T> where;

        public EnumerableDelete(IEnumerable<T> where) {
            this.where = where;
        }

        public int Execute() {
            var source = enumerableSourceFinder.FindSourceOf(where);
            var count = 0;
            foreach (var item in where.ToArray()) {
                source.Remove(item);
                count++;
            }
            return count;
        }
    }
}